load("//tools/skylark:drake_py.bzl", "drake_py_binary")
load("//tools/skylark:py.bzl", "py_binary", "py_library")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_runfiles_binary.bzl",
    "drake_runfiles_binary",
)
load(
    "@drake_visualizer//:defs.bzl",
    _DRAKE_VISUALIZER_ENABLED = "ENABLED",
)

package(default_visibility = ["//visibility:public"])

py_library(
    name = "module_py",
    srcs = ["__init__.py"],
    visibility = [":__subpackages__"],
    deps = ["//:module_py"],
)

_VISUALIZER_MAIN = "{}:drake_visualizer_{}.py".format(
    "//tools/workspace/drake_visualizer",
    "bazel" if _DRAKE_VISUALIZER_ENABLED else "disabled",
)

py_binary(
    name = "drake_visualizer_py",
    srcs = [_VISUALIZER_MAIN],
    data = [
        "//examples:models",
        "@drake_visualizer",
    ] if _DRAKE_VISUALIZER_ENABLED else [],
    main = _VISUALIZER_MAIN,
    python_version = "PY3",
    srcs_version = "PY3",
    deps = [
        "//lcmtypes:lcmtypes_drake_py",
        "//tools/workspace/drake_visualizer:builtin_scripts_py",
        "@drake_visualizer//:drake_visualizer_python_deps",
    ] if _DRAKE_VISUALIZER_ENABLED else [],
)

drake_runfiles_binary(
    name = "drake_visualizer",
    target = ":drake_visualizer_py",
)

alias(
    name = "meldis",
    actual = "//bindings/pydrake/visualization:meldis",
)

alias(
    name = "model_visualizer",
    actual = "//bindings/pydrake/visualization:model_visualizer",
)

drake_py_binary(
    name = "model_visualizer_private",
    testonly = True,
    srcs = ["model_visualizer_private.py"],
    data = ["//:some_test_models"],
    visibility = ["//visibility:private"],
    deps = ["//bindings/pydrake/visualization:model_visualizer"],
)

alias(
    name = "mesh_to_model",
    actual = "//bindings/pydrake/multibody:mesh_to_model",
)

alias(
    name = "fix_inertia",
    actual = "//bindings/pydrake/multibody:fix_inertia",
)

# === config_setting rules ===

# When this is set, a Drake build will promote some warnings to errors.
# See drake/tools/cc_toolchain/bazel.rc for details.
config_setting(
    name = "drake_werror",
    values = {"define": "DRAKE_WERROR=ON"},
)

# We hope to enable Clarabel by default, but for the moment it is opt-in.
# Use `--define=WITH_CLARABEL=ON` on the bazel command line to enable it.
config_setting(
    name = "with_clarabel",
    values = {"define": "WITH_CLARABEL=ON"},
)

config_setting(
    name = "with_gurobi",
    values = {"define": "WITH_GUROBI=ON"},
)

config_setting(
    name = "with_mosek",
    values = {"define": "WITH_MOSEK=ON"},
)

config_setting(
    name = "with_snopt",
    values = {"define": "WITH_SNOPT=ON"},
)

config_setting(
    name = "using_sanitizer",
    values = {"define": "USING_SANITIZER=ON"},
)

config_setting(
    name = "using_memcheck",
    values = {"define": "USING_MEMCHECK=ON"},
)

# CLP is an open-source solver, and is included in the Drake build by
# default. The CLP solver is irrelevant to some users of MathematicalProgram,
# so we provide a hidden switch to shut it off for developers who don't
# actually need it.  This is not a supported configuration. Use at your own
# risk: --define=NO_CLP=ON
config_setting(
    name = "no_clp",
    values = {"define": "NO_CLP=ON"},
)

# CSDP is an open-source solver, and is included in the Drake build by default.
# The CSDP solver is irrelevant to some users of MathematicalProgram, so we
# provide a hidden switch to shut it off for developers who don't actually need
# it. This is not a supported configuration. Use at your own risk:
# --define=NO_CSDP=ON
config_setting(
    name = "no_csdp",
    values = {"define": "NO_CSDP=ON"},
)

# IPOPT is an open-source solver, and is included in the Drake build by
# default. The IPOPT solver is irrelevant to some users of MathematicalProgram,
# so we provide a hidden switch to shut it off for developers who don't
# actually need it.  This is not a supported configuration. Use at your own
# risk: --define=NO_IPOPT=ON
config_setting(
    name = "no_ipopt",
    values = {"define": "NO_IPOPT=ON"},
)

# NLOPT is an open-source solver, and is included in the Drake build by
# default. The NLOPT solver is irrelevant to some users of MathematicalProgram,
# so we provide a hidden switch to shut it off for developers who don't
# actually need it.  This is not a supported configuration. Use at your own
# risk: --define=NO_NLOPT=ON
config_setting(
    name = "no_nlopt",
    values = {"define": "NO_NLOPT=ON"},
)

# OSQP is an open-source solver, and is included in the Drake build by
# default. The OSQP solver is irrelevant to some users of MathematicalProgram,
# so we provide a hidden switch to shut it off for developers who don't
# actually need it.  This is not a supported configuration. Use at your own
# risk: --define=NO_OSQP=ON
config_setting(
    name = "no_osqp",
    values = {"define": "NO_OSQP=ON"},
)

# SCS is an open-source solver, and is included in the Drake build by default.
# The SCS solver is irrelevant to some users of MathematicalProgram, so we
# provide a hidden switch to shut it off for developers who don't actually need
# it. This is not a supported configuration. Use at your own risk:
# --define=NO_SCS=ON
config_setting(
    name = "no_scs",
    values = {"define": "NO_SCS=ON"},
)

add_lint_tests()
